//
// Created by zhulingfeng on 2020/2/26.
//

#ifndef SORTING_SRC_TEST_SORT_TEST_HPP_
#define SORTING_SRC_TEST_SORT_TEST_HPP_

#include <gtest/gtest.h>
#include "list_node.hpp"

class SortTest : public ::testing::Test {
 protected:
  SortTest();
  /**
   * @brief Init test data.
   * @param max_array_length It takes effect only when fix_array_length = -1.
   */
  void Init(int fix_array_length, int max_array_length, int max_array_value,
            int num_test_arrays);
  ~SortTest() override;
  std::vector<std::vector<int>> unsorted_vectors_;
  std::vector<std::vector<int>> sorted_vectors_;
  std::vector<ListNode*> unsorted_lists_;
  std::vector<ListNode*> sorted_lists_;
};

#define ARRAY_SORT_TEST_F_BASE(test_suit, sort_algorithm) \
  TEST_F(test_suit, Array##sort_algorithm) {              \
    for (int i = 0; i < unsorted_vectors_.size(); ++i) {  \
      auto& array = unsorted_vectors_[i];                 \
      sort_algorithm(array);                              \
      EXPECT_EQ(array, sorted_vectors_[i]);               \
    }                                                     \
  }
#define ARRAY_SORT_TEST_F(sort_algorithm) \
  ARRAY_SORT_TEST_F_BASE(SortTest, sort_algorithm)

#define LIST_SORT_TEST_F_BASE(test_suit, sort_algorithm) \
  TEST_F(test_suit, List##sort_algorithm) {              \
    for (int i = 0; i < unsorted_lists_.size(); ++i) {   \
      auto list = unsorted_lists_[i];                    \
      ListNode dummy_output, dummy_gt;                   \
      dummy_output.next = sort_algorithm(list);          \
      dummy_gt.next = sorted_lists_[i];                  \
      EXPECT_EQ(dummy_output, dummy_gt);                 \
    }                                                    \
  }
#define LIST_SORT_TEST_F(sort_algorithm) \
  LIST_SORT_TEST_F_BASE(SortTest, sort_algorithm)

// #define SORT_TEST_F(test_suit_name, sort_algorithm_name, data_type_name)   \
//   TEST_F(test_suit_name, Test##sort_algorithm_name##data_type_name) {      \
//     static_assert(#data_type_name == "Array" || #data_type_name == "List", \
//                   "Unknown data_type_name: ");                             \
//     if (#data_type_name == "Array") {                                      \
//       for (int i = 0; i < unsorted_vectors_.size(); ++i) {                 \
//         auto& array = unsorted_vectors_[i];                                \
//         sort_algorithm_name(array);                                        \
//         EXPECT_EQ(array, sorted_vectors_[i]);                              \
//       }                                                                    \
//     } else {                                                               \
//       for (int i = 0; i < unsorted_lists_.size(); ++i) {                   \
//         auto list = unsorted_lists_[i];                                    \
//         ListNode dummy_output, dummy_gt;                                   \
//         dummy_output.next = sort_algorithm_name(list);                     \
//         dummy_gt.next = sorted_lists_[i];                                  \
//         EXPECT_EQ(dummy_output, dummy_gt);                                 \
//       }                                                                    \
//     }                                                                      \
//   }
#endif  // SORTING_SRC_TEST_SORT_TEST_HPP_
